{include file="public/top"}
<article class="page-container">
    <form id="form-question-add" class="form-horizontal" role="form" action="" method="post"
          enctype="multipart/form-data">
        {:token()}
        <div class="row cl" style="padding-top:20px;margin-left:-40px;">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属题库：</label>
            <div class="formControls col-xs-8 col-sm-9">
            <span class="select-box" style="width:150px;">
                <select name="qbank_id" class="select" size="1">
                    {volist name="bankList" id="cate"}
                        <option value="{$cate.bid}" {if condition="($cate.bid==$question.qbank)" } selected{/if}>{$cate.bank_name}</option>
                    {/volist}
                </select>
            </span>
            </div>
        </div>
        <div class="row cl" style="padding-top:20px;margin-left:-40px;">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>题目种类：</label>
            <div class="formControls col-xs-8 col-sm-9">
            <span class="select-box" style="width:150px;">
                <select name="qtype_id" class="select" onchange="test()" size="1">
                    <option value="" selected>请选择题目种类</option>
                    {volist name="typeList" id="cate"}
                        <option value="{$cate.qtype}" {if condition="($cate.qtype==$question.qtype)" } selected{/if}>{$cate.type_name}</option>
                    {/volist}
                </select>
            </span>
            </div>
        </div>

        <div id="q_num" class="row cl" style="padding-top:20px;margin-left:-40px;
             {if condition="($question.qtype==1) OR($question.qtype==2)"}{else /}display:none{/if}">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>答案个数：</label>
            <div class="formControls col-xs-8 col-sm-9">
            <span class="select-box" style="width:150px;">
                <select name="qnum" class="select selector" onchange="changeAns()" size="1">
                    <option value="" selected>----</option>
                    {php}
                    $a=count((array)json_decode(htmlspecialchars_decode($question->qans)));
                    for($i=3;$i<7;$i++){
                     echo "<option value=".$i;
                                  if($i==$a){
                                  echo " selected";
                                  }
                    echo ">".$i."</option>";}
                    {/php}
                </select>
            </span>
            </div>
        </div>

        <div class="row cl" style="padding-top:20px;margin-left:-40px;">
            <label for="content" class="form-label col-xs-4 col-sm-2">题目内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="content" name="content" type="text/plain">{$question.content}</script>
            </div>
        </div>
        <div class="row cl" style="padding-top: 20px;margin-left:-40px;">
            <label for="content" class="form-label col-xs-4 col-sm-2">答案：</label>

            {php}
            if($question->qans){
            $qans=json_decode(htmlspecialchars_decode($question->qans));
            echo "<div id='q_type".$question->qtype."' class='formControls col-xs-8 col-sm-9' style=''>";
            $anss='';
            foreach((array)$qans as $key=>$value){
            $anss.="<label>".$key.":</label><input class='input-text' name='q_type".$question->qtype.".".$key."' type='text' value='".$value."'><br>";
            }
            $anss=substr($anss,0,strlen($anss)-4);
            echo $anss;
            }
            {/php}</div>
            <!--题型1，2区块-->
            <div id="q_type1" class="formControls col-xs-8 col-sm-9" style="display: none">
            </div>
            <div id="q_type2" class="formControls col-xs-8 col-sm-9" style="display: none">
            </div>
            <!--题型3区块-->
            <div id="q_type3" class="formControls col-xs-8 col-sm-9" style="display: none">
                <label>A:</label><input class="input-text" name="q_type3.A" type="text"><br>
                <label>B:</label><input class="input-text" name="q_type3.B" type="text">
            </div>
        </div>
        </div>
        <div class="row cl" style="padding-top: 20px;margin-left:-40px;">
            <label for="content" class="form-label col-xs-4 col-sm-2">正确答案：</label>
            <div id="qa" class="formControls col-xs-8 col-sm-9" style="">
                <input class="input-text" name="qa" type="text" placeholder="正确答案编号，单选多选判断直接填写编号，填空问答留空"><br>
            </div>
        </div>
        <div class="row cl" style="padding-top:20px;margin-left:40px;">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__ADMIN__/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/ueditor/1.4.3/ueditor.all.min.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/ueditor/1.4.3/ueditor.all.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    $(function () {
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });


    });
</script>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('content', {initialFrameWidth: 600, initialFrameHeight: 400,});
</script>
<script type="text/javascript">

    function test() {
        var vals = $("select[name='qtype_id']").val();
        $("#q_num").hide();
        for (var i = 1; i < "7"; i++) {
            var v = "q_type" + vals;

            if (i == vals) {

                $("#q_type" + i).show();
        alert(i);
            } else {
                $("#q_type" + i).hide();
            }
            if (vals == "1" || vals == "2") {

                var test = document.getElementById('q_num');
                $("#q_num").show();
                $(".selector").val("");


            }
        }
    }

    function changeAns() {
        var vals = $("select[name='qnum']").val();
        var type = $("select[name='qtype_id']").val();
        var p = document.getElementById('q_type' + type);
        var childs = p.childNodes;

        for (var i = childs.length - 1; i >= 0; i--) {
            p.removeChild(childs[i]);
        }
        var arr = ["A", "B", "C", "D", "E", "F"]
        for (var i = 0; i < vals; i++) {
            var input = document.createElement("input");
            input.setAttribute("type", "text");
            input.setAttribute("name", "q_type" + type + "." + arr[i]);
            input.setAttribute("class", "input-text");
            var br = document.createElement("br");
            var label = document.createElement("laber");
            label.innerText = arr[i] + ":";
            p.appendChild(label);
            p.appendChild(input);
            p.appendChild(br);

        }

    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
{include file="public/footer"}